require(["./config"], () => {
  require([
    "template",
    "request",
    "header",
    "footer",
    "bootstrap",
    "ddb",
    "land",
    "jquery",
  ], (tmp, req) => {
    class Index {
      constructor() {
        this.carousel();
        this.getPai();
      }

      // 轮播图
      carousel() {
        let count = 1;
        $("#flash1").onmouseenter = function () {
          count = 1;
          $("#slide1").css("display", "block");
          $("#slide2").css("display", "none");

          $("#flash1").addClass = "flash-show";
          $("#flash2").addClass = "flash-hidden";
        };
        $("#flash2").onmouseenter = function () {
          count = 2;
          $("#slide2").css("display", "block");
          $("#slide1").css("display", "none");

          $("#flash1").addClass = "flash-hidden";
          $("#flash2").addClass = "flash-show";
        };

        var loop = setInterval(function () {
          if (count === 2) {
            count = 1;
            $("#slide1").css("display", "block");
            $("#slide2").css("display", "none");

            $("#flash1").addClass = "flash-show";
            $("#flash2").addClass = "flash-hidden";
            count--;
          } else {
            $("#slide2").css("display", "block");
            $("#slide1").css("display", "none");

            $("#flash1").addClass = "flash-hidden";
            $("#flash2").addClass = "flash-show";
            count++;
          }
          //   console.log(count);
        }, 2000);
      }

      //获取 PAI赛事限定 数据
      getPai() {
        req.getIndexsugar1().then((res) => {
          //   渲染页面
          if (res.code === 1) {
            this.renderPai(res.result_body);
          }
        });
      }
      // 渲染 PAI赛事限定
      renderPai(res) {
        const html = tmp("template_PAI", { list: res });
        $(".temPAI").html(html);
        // console.log(html);
      }
      //
    }
    return new Index();
  });
});
